package cn.wps.moffice.main.cloud.storage.core.service.internal.googledrive; import android.content.Intent; import android.os.Build; import android.text.TextUtils; import cn.wps.moffice.OfficeApp; import cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI; import cn.wps.moffice.main.cloud.storage.core.service.internal.googledrive.GoogleLoginTransferActivity; import cn.wps.moffice.main.cloud.storage.model.CSFileData; import cn.wps.moffice.main.cloud.storage.model.CSSession; import cn.wps.moffice_eng.R; import com.google.android.gms.auth.GoogleAuthException; import com.google.android.gms.auth.GooglePlayServicesAvailabilityException; import com.google.android.gms.auth.UserRecoverableAuthException; import com.google.android.gms.common.GoogleApiAvailability; import defpackage.fqr; import defpackage.fqx; import defpackage.zbj; import defpackage.zdd; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.slf4j.Logger; import org.slf4j.Marker; public class NewGoogleDriveAPI extends AbsCSAPI { private static final String[] gnw = {"https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.metadata", "https://www.googleapis.com/auth/drive.file"}; private static final zag gnx; private static final zbc gny = zbj.a.ANX; private CSFileData gmy; private zdd gnA; private yyx gnz; static { boolean z = true; if (Build.VERSION.SDK_INT < 9) { z = false; } gnx = z ? new zay() : new zar(); } public NewGoogleDriveAPI(String str) { super(str); OfficeApp arx = OfficeApp.arx(); List asList = Arrays.asList(gnw); zbp.checkArgument(asList != null && asList.iterator().hasNext()); yyx yyx = new yyx(arx, "oauth2: " + new zcg(new zbo(String.valueOf(' '))).APX.a(new StringBuilder(), asList.iterator()).toString()); yyx.ALa = new zcc(); this.gnz = yyx; if (this.gmn != null) { try { bCb(); } catch (fte e) { e.printStackTrace(); } } } private CSFileData a(zdf zdf) { CSFileData cSFileData = new CSFileData(); cSFileData.setFileId(zdf.id); cSFileData.setName(zdf.name); cSFileData.setModifyTime(Long.valueOf(zdf.modifiedTime.value)); cSFileData.setFolder(fqr.a.FOLDER.mimeType.equals(zdf.mimeType)); long longValue = zdf.size == null ? 0 : zdf.size.longValue(); String str = zdf.mimeType; if (fqr.a.GDOC.ss(str) || fqr.a.GSHEET.ss(str) || fqr.a.GSLIDES.ss(str)) { longValue = -1; cSFileData.setRevision("1"); } cSFileData.setFileSize(longValue); cSFileData.setCreateTime(Long.valueOf(zdf.createdTime.value)); cSFileData.setRefreshTime(Long.valueOf(fun.bHG())); cSFileData.setMimeType(zdf.mimeType); List<String> list = zdf.parents; if (list != null) { cSFileData.setParents(list); } cSFileData.setPath(zdf.id); String str2 = zdf.name; String str3 = zdf.mimeType; if (!TextUtils.isEmpty(str2) && fqr.a.GDOC.ss(str3)) { str2 = str2.concat(".").concat(fqr.a.GDOC.name().toLowerCase()); } else if (fqr.a.GSHEET.ss(str3)) { str2 = str2.concat(".").concat(fqr.a.GSHEET.name().toLowerCase()); } else if (fqr.a.GSLIDES.ss(str3)) { str2 = str2.concat(".").concat(fqr.a.GSLIDES.name().toLowerCase()); } cSFileData.setName(str2); return cSFileData; } private static InputStream a(zdd zdd, zdf zdf) { if (zdf == null) { return null; } try { return fqr.a.GDOC.mimeType.equals(zdf.mimeType) ? zdd.gLl().m253if(zdf.id, fqr.b.DOCX.mimeType).gKw() : fqr.a.GSHEET.mimeType.equals(zdf.mimeType) ? zdd.gLl().m253if(zdf.id, fqr.b.XLSX.mimeType).gKw() : fqr.a.GSLIDES.mimeType.equals(zdf.mimeType) ? zdd.gLl().m253if(zdf.id, fqr.b.PPTX.mimeType).gKw() : zdd.gLl().aet(zdf.id).gKw(); } catch (IOException e) { fqn.c("GoogleDrive", "download exception...", e); return null; } } public static String a(yyx yyx) { try { String token = yyx.getToken(); new StringBuilder("token:").append(token); return token; } catch (GooglePlayServicesAvailabilityException e) { e.getMessage(); e.printStackTrace(); return null; } catch (UserRecoverableAuthException e2) { e2.printStackTrace(); GoogleLoginTransferActivity.B(e2.mIntent == null ? null : new Intent(e2.mIntent)); new StringBuilder("token:").append(e2.getCause()); return null; } catch (IOException e3) { e3.printStackTrace(); new StringBuilder("token:").append(e3.getMessage()); return null; } catch (GoogleAuthException e4) { e4.printStackTrace(); new StringBuilder("token:").append(e4.getMessage()); return null; } } private static List<zdf> a(zdd zdd, String str) throws fte { ArrayList arrayList = new ArrayList(); try { zdd.b.d gLm = zdd.gLl().gLm(); do { try { zdd.b.d aex = gLm.aev(Marker.ANY_MARKER); aex.q = "trashed=false and '" + str + "' in parents"; zdg zdg = (zdg) aex.execute(); arrayList.addAll(zdg.files); gLm.pageToken = zdg.nextPageToken; } catch (yza e) { throw new fte(-900); } catch (IOException e2) { gLm.pageToken = null; } if (gLm.pageToken == null) { break; } } while (gLm.pageToken.length() > 0); } catch (IOException e3) { } return arrayList; } private static zdf a(zdd zdd, String str, String str2) { try { zdf zdf = new zdf(); zdf.name = str2; new StringBuilder("begin rename a file! \n newTitle: ").append(str2); zdd.b.e a = zdd.gLl().a(str, zdf); a.aev("name"); zdf zdf2 = (zdf) a.execute(); new StringBuilder("end rename a file! \n").append(zdf.gKN()); return zdf2; } catch (IOException e) { return null; } } private static zdf a(zdd zdd, String str, String str2, String str3) { try { zdf zdf = new zdf(); yzq yzq = new yzq(str2, new File(str3)); return yzq.getLength() == 0 ? (zdf) zdd.gLl().aet(((zdf) zdd.gLl().a(str, zdf).execute()).id).aev(Marker.ANY_MARKER).execute() : (zdf) zdd.gLl().aet(((zdf) zdd.gLl().a(str, zdf, yzq).execute()).id).aev(Marker.ANY_MARKER).execute(); } catch (IOException e) { fqn.c("GoogleDrive", "updateFile exception...", e); return null; } } private static zdf a(zdd zdd, String str, String str2, String str3, String str4, String str5) { zdf zdf = new zdf(); zdf.name = str; zdf.description = str2; zdf.mimeType = str4; if (str3 != null && str3.length() > 0) { if (Logger.ROOT_LOGGER_NAME.equals(str3)) { str3 = str3.toLowerCase(); } zdf.parents = Arrays.asList(str3); } yzq yzq = new yzq(str4, new File(str5)); try { zdf zdf2 = yzq.getLength() == 0 ? (zdf) zdd.gLl().b(zdf).aev(Marker.ANY_MARKER).execute() : (zdf) zdd.gLl().a(zdf, yzq).aev(Marker.ANY_MARKER).execute(); new StringBuilder("File ID: %s").append(zdf2.id); return zdf2; } catch (IOException e) { fqn.c("GoogleDrive", "insertFile exception...", e); return null; } } private static zdf b(zdd zdd, String str) throws fte, IOException { try { zdf zdf = (zdf) zdd.gLl().aet(str).aev(Marker.ANY_MARKER).execute(); if (!zdf.trashed.booleanValue()) { return zdf; } throw new fte(-2); } catch (IOException e) { throw e; } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void bCb() throws fte { if (this.gmn != null) { String username = this.gmn.getUsername(); if (!lwv.isEmpty(username)) { this.gnz.adF(username); this.gnA = new zdd(new zdd.a(gnx, gny, this.gnz).adN("WPS Office/" + OfficeApp.arx().arC())); bEA(); } } } @Override // defpackage.fqx public final CSFileData a(String str, String str2, ftg ftg) throws fte { String sq; String str3 = str2 + ".tmp"; try { lul.fa(str2, str3); String IR = lwv.IR(str2); try { sq = fqr.b.st(str2).mimeType; } catch (Exception e) { sq = fqr.sq(str2); } zdf a = a(this.gnA, IR, IR, str, sq, str3); if (a != null) { CSFileData a2 = a(a); lul.Ip(str3); return a2; } lul.Ip(str3); return null; } catch (Exception e2) { throw new fte(e2); } catch (Throwable th) { lul.Ip(str3); throw th; } } @Override // defpackage.fqx public final CSFileData a(String str, String str2, String str3, ftg ftg) throws fte { String sq; String str4 = str3 + ".tmp"; try { lul.fa(str3, str4); lwv.IR(str3); try { sq = fqr.b.st(str3).mimeType; } catch (Exception e) { sq = fqr.sq(str3); } zdf a = a(this.gnA, str, sq, str4); if (a != null) { CSFileData a2 = a(a); lul.Ip(str4); return a2; } lul.Ip(str4); return null; } catch (Exception e2) { throw new fte(e2); } catch (Throwable th) { lul.Ip(str4); throw th; } } @Override // defpackage.fqx public final List<CSFileData> a(CSFileData cSFileData) throws fte { List<zdf> a = a(this.gnA, cSFileData.getFileId()); if (a.size() <= 0) { return null; } ArrayList arrayList = new ArrayList(); for (int i = 0; i < a.size(); i++) { zdf zdf = a.get(i); if (zdf != null) { arrayList.add(a(zdf)); } } return arrayList; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final void a(final fqx.a aVar) throws fte { GoogleLoginTransferActivity.a(new GoogleLoginTransferActivity.a() { /* class cn.wps.moffice.main.cloud.storage.core.service.internal.googledrive.NewGoogleDriveAPI.AnonymousClass1 */ @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.googledrive.GoogleLoginTransferActivity.a public final void nt(final String str) { if (!lwv.isEmpty(str)) { NewGoogleDriveAPI.this.gnz.adF(str); fcx.p(new Runnable() { /* class cn.wps.moffice.main.cloud.storage.core.service.internal.googledrive.NewGoogleDriveAPI.AnonymousClass1.AnonymousClass1 */ public final void run() { if (NewGoogleDriveAPI.a(NewGoogleDriveAPI.this.gnz) != null) { NewGoogleDriveAPI.this.gmn = new CSSession(); NewGoogleDriveAPI.this.gmn.setKey(NewGoogleDriveAPI.this.fIH); NewGoogleDriveAPI.this.gmn.setLoggedTime(System.currentTimeMillis()); NewGoogleDriveAPI.this.gmn.setUserId(str); NewGoogleDriveAPI.this.gmn.setUsername(str); NewGoogleDriveAPI.this.gmn.setToken(str); NewGoogleDriveAPI.this.glC.b(NewGoogleDriveAPI.this.gmn); try { NewGoogleDriveAPI.this.bCb(); aVar.bzJ(); } catch (fte e) { e.printStackTrace(); aVar.sD(null); } } } }); } } }); GoogleLoginTransferActivity.bEU(); } @Override // defpackage.fqx public final boolean a(CSFileData cSFileData, String str, ftg ftg) throws fte { try { a(str, a(this.gnA, b(this.gnA, cSFileData.getFileId())), cSFileData.getFileSize(), ftg); return true; } catch (IOException e) { if (fun.b(e)) { throw new fte(-6, e); } throw new fte(-5, e); } } @Override // defpackage.fqx public final boolean bE(String str, String str2) throws fte { return a(this.gnA, str, str2) != null; } @Override // defpackage.fqx public final CSFileData bEA() throws fte { if (this.gmy == null) { if (fcz.btO()) { return null; } CSFileData cSFileData = new CSFileData(); cSFileData.setFileId(Logger.ROOT_LOGGER_NAME); cSFileData.setName(OfficeApp.arx().getString(R.string.gdoc)); cSFileData.setFolder(true); cSFileData.setRefreshTime(Long.valueOf(fun.bHG())); cSFileData.setPath(Logger.ROOT_LOGGER_NAME); this.gmy = cSFileData; } return this.gmy; } @Override // defpackage.fqx public final boolean bEx() { this.glC.a(this.gmn); this.gmn = null; return true; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final String bEy() throws fte { return ""; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final boolean bEz() { return GoogleApiAvailability.gkO().isGooglePlayServicesAvailable(OfficeApp.arx()) == 0; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final String getRedirectUrl() { return ""; } @Override // cn.wps.moffice.main.cloud.storage.core.service.internal.AbsCSAPI, defpackage.fqx public final boolean q(String... strArr) throws fte { return false; } @Override // defpackage.fqx public final CSFileData sK(String str) throws fte { try { zdf b = b(this.gnA, str); if (b != null) { return a(b); } throw new fte(-2, ""); } catch (IOException e) { if (fun.b(e)) { throw new fte(-6, e); } throw new fte(-5, e); } } }